class Solution {
    public int lengthOfLastWord(String s) {
        int slow = 0, fast = 0;
        int n = s.length();
        int ret = 0;
        while (slow < n) {
            while (slow < n && s.charAt(slow) == ' ') {
                slow++;
            }
            if (slow >= n) break;
            fast = slow;
            while (fast < n && s.charAt(fast) != ' ') {
                fast++;
            }
            ret = fast - slow;
            slow = fast;
        }
        return ret;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.lengthOfLastWord("luffy is still joyboy"));
    }
}